/**
 * Copyright 2008 by Robert Konigsberg
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the same terms as Perl.
 *
 * @see http://www.perl.com/perl/misc/Artistic.html
 */
package visitor.surveyor;

import org.testng.annotations.*;

@Test
public class TranslatedArrayTest {

  @Test
  public void testOffsets() {
    TranslatedArray a = new TranslatedArray(-2, 4, -1, 3);
    assert a.getMinX() == -2;
    assert a.getMinY() == -1;
    assert a.getMaxX() == 4;
    assert a.getMaxY() == 3;
  }

  @Test(dataProvider= "supplier")
  public void successTests(Integer x, Integer y, Character c) {
    TranslatedArray a = new TranslatedArray(-2, 2, -1, 3);
    a.set(x, y, c);
    assert a.get(x, y) == c;
  }

  @Test(dataProvider= "supplier2", expectedExceptions = IndexOutOfBoundsException.class)
  public void outOfBoundsSetters(Integer x, Integer y) {
    TranslatedArray a = new TranslatedArray(-2, 2, -1, 3);
    a.set(x, y, 'z');
  }

  @Test(dataProvider= "supplier2", expectedExceptions = IndexOutOfBoundsException.class)
  public void outOfBoundsGetters(Integer x, Integer y) {
    TranslatedArray a = new TranslatedArray(-2, -1, 2, 3);
    a.get(x, y);
  }

  @DataProvider(name = "supplier")
  Object[][] supplier() {
    return new Object[][] {
      arry(-2, -1, 'a'),
      arry(-2, 0, 'b'),
      arry(-2, 1, 'd'),
      arry(-2, 2, 'd'),
      arry(-2, 3, 'e'),

      arry(-1, -1, 'f'),
      arry(-1, 0, 'g'),
      arry(-1, 1, 'h'),
      arry(-1, 2, 'i'),
      arry(-1, 3, 'j'),

      arry(0, -1, 'k'),
      arry(0, 0, 'l'),
      arry(0, 1, 'm'),
      arry(0, 2, 'n'),
      arry(0, 3, 'o'),

      arry(1, -1, 'p'),
      arry(1, 0, 'q'),
      arry(1, 1, 'r'),
      arry(1, 2, 's'),
      arry(1, 3, 't'),

      arry(2, -1, 'u'),
      arry(2, 0, 'v'),
      arry(2, 1, 'w'),
      arry(2, 2, 'x'),
      arry(2, 3, 'y'),
    };
  }

  @DataProvider(name = "supplier2")
  Object[][] supplier2() {
    return new Object[][] {
      arry(-3, 0),
      arry(4, 0),
      arry(0, -2),
      arry(0 , 4)
    };
  }

  static Object[] arry(Object... arry) {
    return arry;
  }
}
